<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/23
 * Time: 16:43
 */

namespace HiCommon\Model;



class RoadRescueOrder extends Base
{
    protected $table = 'road_rescue_order';
    protected $guarded = [];


    //关联店铺信息
    public function to_shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id');
    }

    //关联店铺信息
    public function apprise()
    {
        return $this->hasOne(UsersApprise::class, 'order_id')->where(['type'=>15]);
    }

    //关联用户信息
    public function user()
    {
        return $this->belongsTo(Users::class, 'user_id');
    }

    //关联用户信息
    public function user_apprise()
    {
        return $this->belongsTo(UsersApprise::class,'id', 'order_id')->where(['type' => 15]);
    }


    //关联评论信息


    /**
     * 获取状态对应的名称
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getPayTypeAttribute($value)
    {
        switch ($value)
        {
            case 1:
                $res = ['id'=>1,'name'=>'微信'];
                break;
            case 2:
                $res = ['id'=>2,'name'=>'支付宝'];
                break;
            default:
                $res = ['id'=>-1,'name'=>'未知'];
        }
        return $res;
    }


    /**
     * 获取状态对应的名称
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getPayStatusAttribute($value)
    {
        switch ($value)
        {
            case 1:
                $res = ['id'=>1,'name'=>'已支付'];
                break;
            case 2:
                $res = ['id'=>2,'name'=>'未支付'];
                break;
            default:
                $res = ['id'=>-1,'name'=>'未知'];
        }
        return $res;
    }


    /**
     * 获取状态对应的名称
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getStatusAttribute($value)
    {
        switch ($value)
        {
            case 0:
                $res = ['id'=>0,'name'=>'待支付'];
                break;
            case 1:
                $res = ['id'=>1,'name'=>'待处理'];
                break;
            case 2:
                $res = ['id'=>2,'name'=>'申请退款'];
                break;
            case 21:
                $res = ['id'=>21,'name'=>'退款失败'];
                break;
            case 22:
                $res = ['id'=>22,'name'=>'退款成功'];
                break;
            case 3:
                $res = ['id'=>3,'name'=>'已完成'];
                break;
            case 4:
                $res = ['id'=>4,'name'=>'订单已过期'];
                break;
            default:
                $res = ['id'=>-1,'name'=>'未知'];
        }
        return $res;
    }



}